import React, { FC }from 'react'
import { HashRouter as Router, Routes, Route, useLocation, useNavigate } from "react-router-dom"
import { NavBar, TabBar } from 'antd-mobile'
import {
    AppOutline,
    MessageOutline,
    UnorderedListOutline,
    UserOutline,
} from 'antd-mobile-icons'

import Home from '../pages/Home'
import Service from '../pages/Service'
import News from '../pages/News'
import Mine from '../pages/Mine'
import Education from '../pages/Education'
import Edit from '../pages/Mine/Edit'


const Bottom: FC = () => {
    const history = useNavigate();
    const location = useLocation()
    const { pathname } = location

    const setRouteActive = (value: string) => {
        history(value);
    }

    const tabs = [
        {
            key: '/',
            title: '首页',
            icon: <AppOutline />,
        },
        {
            key: '/service',
            title: '服务',
            icon: <UnorderedListOutline />,
        },
        {
            key: '/news',
            title: '新闻',
            icon: <MessageOutline />,
        },
        {
            key: '/mine',
            title: '我的',
            icon: <UserOutline />,
        },
    ]

    return (
        <TabBar activeKey={pathname} onChange={value => setRouteActive(value)}>
            {tabs.map(item => (
                <TabBar.Item key={item.key} icon={item.icon} title={item.title} />
            ))}
        </TabBar>
    )
}

export default function index() {
    return (
        <Router>
            <Routes>
                <Route path='/' element={<Home></Home>} ></Route>
                <Route path='/service' element={<Service></Service>} ></Route>
                <Route path='/news' element={<News></News>} ></Route>
                <Route path='/mine' element={<Mine></Mine>} ></Route>
                <Route path='/education/index' element={<Education></Education>} ></Route>
                <Route path='/mine/edit' element={<Edit></Edit>} ></Route>

            </Routes>
            <div className='bottom'>
            <Bottom></Bottom>
            </div>
        </Router>
    )
}
